Ext.define('AM.view.PerformanceFormView',{
	extend: 'Ext.form.Panel',
	alias : 'widget.performanceFormView',
	layout : "form",
	items: [{
			   layout : "column",
			   border : false,
					 items: [{
							columnWidth :.24,
							layout : "form",
							border : false,
							labelWidth : 30,
							   	items: [{
							   			  xtype : "datefield",
							   			  fieldLabel: '	查询日期',
							   			  labelAlign :"right",
							   			  id:'rewarddate',
									      name: 'searchdate',
									      format:'Y-m-d'
								 }]		
						},{
							columnWidth :.24,
							layout : "form",
							border : false,
							labelWidth : 30,
							   	items: [{
										 xtype : "combobox",
									     allowBlank:false,
									     emptyText:'请选择科室',
										 selectOnFocus:true,
										 forceSelection: true,
										 queryMode: 'local',
										 labelAlign :"right",
										 fieldLabel: '科     室',
										 name: 'searchdepartment',
										 store :"TargetDepartStore",
										 displayField: 'name',
			    						 valueField: 'id',
			    						 listeners:{   
												select:function(combo, record,index){
													 try{ 
													 var rewar;
													 var date=Ext.getCmp('rewarddate').getValue();
													 var date1=Ext.util.Format.date(date, 'Y-m');
													 Ext.Ajax.request({
															url : 'departmentFinaceAction_deptfinace',
														    async : false,
															success : function(response, options) {
																var re =Ext.JSON.decode(response.responseText);
																rewar=re.rewad;
															},
															failure : function() {
																Ext.MessageBox.alert("提示", "科室本月无测算奖金！");
															},
															params : {
																dept:this.value,
																date:date1
															}
														});	
														
														 var parent=Ext.getCmp('reward_1');
														 parent.reset( )
														 parent.setValue(rewar);													 
													 }
													 catch(ex){
														 Ext.MessageBox.alert("错误","数据加载失败。");
													 }
												}
										}
							   	}]
						},{
							columnWidth :.2,
							layout : "form",
							border : false,
							labelWidth : 30,
							   	items: [{
							   			  xtype : "numberfield",
							   			  hideTrigger: true, 
							   			  minValue: 0,
							   			  id:'reward_1',
							   			  fieldLabel: '	科室奖金',
							   			  readOnly:true,
							   			  labelAlign :"right",
									      name: 'totalReward',
									      nanText:"输入必须为数字"
									     
								 }]	
						
						}
//						,
//							{
//							columnWidth :.24,
//							layout : "form",
//							border : false,
//								 items: [
//								 	{
//								 	 fieldLabel: '程序化所占比例',
//									 xtype:"combobox",
//								     labelAlign :"right",
//								     selectOnFocus:true,
//									 queryMode: 'local',
//									 name: 'baifenbi',
//									 forceSelection: true,  
//									 store :Ext.create('Ext.data.Store', {
//												    fields: ['id','name'],
//												    data : [
//														      {"id":70, "name":"70"},
//														      {"id":75, "name":"75"},
//														      {"id":80, "name":"80"},
//												              {"id":85, "name":"85"},
//												              {"id":90, "name":"90"},
//														      {"id":95, "name":"95"},
//														      {"id":100, "name":"100"}
//												        ]
//										 		}),
//									 displayField: 'name',
//	    							 valueField: 'id'
//								 	}]
//						}
						]
	 }],
	  buttons: [
	  			 {text: '查询',
	  				 handler: function() {
				            var form = this.up('form').getForm();
				            var searchdateField =form.findField('searchdate');
				            var depart =form.findField('searchdepartment');
				            var searchdepart = depart.getValue();
				            var searchValue = searchdateField. getRawValue();
//				            var searchValue = searchdateField.getValue();//此方法获得不了具体日期
				            if (form.isValid()) {
				                form.submit({
				                    url:'performance_ListPerformance',
				                    success: function(form, action) {  
				                     Ext.getCmp('performanceGridView').getStore().on('beforeload', function (store, options) {
                                     	  var new_params = {searchValue:Ext.util.Format.date(searchValue, 'Y-m'),searchdepart:searchdepart}
                                    	  Ext.apply(store.proxy.extraParams, new_params);
                                  	  });
				                    Ext.getCmp('performanceGridView').getStore().load();
				                    },
				                    failure: function(form, action) {
				                   		 Ext.Msg.alert('查询失败','暂无此月信息' );
								   }
									   
							  });
				            }
				        }
	 			 },{
				        text: '计算奖金',
				        handler: function() {
				            var form = this.up('form').getForm();
				            var searchdateField =form.findField('searchdate');
				            var searchValue = searchdateField.getValue();
				            var depart =form.findField('searchdepartment');
				            var searchdepart = depart.getValue();
				            if (form.isValid()) {
				                form.submit({
				                	url: 'performance_jisuanPerformance',
				                    success: function(form, action) {  
				                    	Ext.getCmp('performanceGridView').getStore().on('beforeload', function (store, options) {
                                     	  var new_params = {searchValue:Ext.util.Format.date(searchValue, 'Y-m'),searchdepart:searchdepart}
                                    	  Ext.apply(store.proxy.extraParams, new_params);
                                  	  });
                                     Ext.getCmp('performanceGridView').getStore().reload();
                                     
				                    },
				                    failure: function(form, action) {
				                   		 Ext.Msg.alert('计算失败', '请检查输入是否正确');
								   }	   
							  });
				            }
				        }
				 },{
				     text: '重新设置',
				     handler : function() {
								this.up('form').getForm().reset();
							}
			 },{
			 	   text: '导出奖金',
				    handler : function() {
				    	    var form = this.up('form').getForm();
				            var searchdateField =form.findField('searchdate');
				            var searchValue = Ext.util.Format.date( searchdateField.getValue(), 'Y-m');
				            var depart =form.findField('searchdepartment');
				            var searchdepart = depart.getValue();
							  window.location.href ="exportExecleAction?dept="+searchdepart+"&searchdate="+searchValue+" ";
							
					}

			 }]
});
